<template>
  <div class="orderlist">
    <!-- tab选项卡 -->
    <div>
      <el-tabs v-model="search.status" @tab-click="tabClick">
        <el-tab-pane
          :label="item.name + '(' + item.num + ')'"
          :name="item.name == '全部' ? '' : item.name"
          v-for="item in detail"
          :key="item.id"
        ></el-tab-pane>
      </el-tabs>
    </div>
    <!-- 搜索 -->
    <div style="margin-top: 18px">
      <!-- {{ search }} -->
      <el-form
        :model="search"
        status-icon
        ref="ruleForm"
        label-width="100px"
        :inline="true"
      >
        <el-form-item label="输入订单编号" prop="orderid">
          <el-input v-model="search.orderid" placeholder="订单编号"></el-input>
        </el-form-item>
        <el-form-item label="申请时间" prop="date">
          <el-date-picker
            v-model="search.date"
            type="datetime"
            placeholder="选择日期时间"
            align="right"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理状态" prop="status">
          <el-input v-model="search.status" placeholder="订单状态"></el-input>
        </el-form-item>
        <el-form-item style="margin-left: 25vw">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >搜索</el-button
          >
          &emsp;
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        border
        ref="multipleTable"
        :data="refundDetail"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="orderid" label="退款单号" width="180">
        </el-table-column>
        <el-table-column label="申请时间" width="240">
          <template slot-scope="scope">{{ scope.row.date }}</template>
        </el-table-column>
        <el-table-column prop="operator" label="用户账号" width="180">
        </el-table-column>
        <el-table-column
          prop="shopid"
          label="退款金额"
          show-overflow-tooltip
          width="180"
        >
        </el-table-column>
        <el-table-column prop="shopname" label="所属门店"></el-table-column>
        <el-table-column
          label="申请状态"
          width="180"
          prop="op_type"
        ></el-table-column>
        <el-table-column label="处理时间" width="240">
          <template slot-scope="scope">{{ scope.row.createAt }}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="checkOrder(scope.row)">
              <b style="color: #409eff"> 查看订单 </b>
              </el-button
            >
          </template>
        </el-table-column>
      </el-table>
     
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagnations.currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagnations.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagnations.total"
        >
        </el-pagination>
        <DrawClear :visibleShow="List"  v-if="visible" @close="visible=false"></DrawClear>
      </div>
    </div>
  </div>
</template>
<script>
import { GetRefundDetail, GetDetail } from "@/api/order";
import DrawClear from "@/components/DrawClear.vue"
export default {
  components: {
    DrawClear
  },
  created() {
    //获取订单统计数据
    GetDetail().then((res) => {
      this.detail = res.data.list;
    });
    this.getRefundDetail();
    // 处理状态
  },
  data() {
    return {
      visible:false,
      //  退款弹框
      List:{},
      // 弹框
      shenqing: "", //申请状态
      detail: [], //静态统计数据
      refundDetail: [], //订单列表
      pagnations: {}, //分页数据
      search: { name: "" }, //查询条件
    };
  },
  methods: {
    checkOrder(e) {
      this.dialogVisible = true;
      this.List = e
      this.visible=true
    },
    handleClose(done) {
      done();
    },
    // 处理size变化
    handleSizeChange(val) {
      // 当每页多少条发生变化时候，重新更新搜索条件size
      // 重新获取员工列表
      // console.log(`每页 ${val} 条`);
      this.search.size = val;
      this.getRefundDetail();
    },
    // 处理current变化
    handleCurrentChange(val) {
      // 当当前页发生变化时候更新 搜索条件的当前页
      // 获取数据
      this.search.current = val;
      this.getRefundDetail();
    },
    tabClick(tab) {
      this.submitForm(tab.name);
      //   console.log(tab);
      this.getRefundDetail();
    },
    //搜索
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.getRefundDetail();
        } else {
          return false;
        }
      });
    },
    //重置
    resetForm(formName) {
      this.search.createEnd = "";
      this.$refs[formName].resetFields();
      // console.log(this.$refs[formName]);
    },
    //获取订单列表（这个方法会多次执行）
    getRefundDetail() {
      if (this.search.status == 0) {
        this.search.status = "";
      }
      GetRefundDetail(this.search)
        .then((res) => {
          this.refundDetail = res.data.data;
          this.refundDetail.map((item) => {
            if (item.op_type == 2) {
              return (item.op_type = "已退款");
            } else if (item.op_type == 3) {
              return (item.op_type = "已拒绝");
            } else {
              return (item.op_type = "待处理");
            }
          });
          this.pagnations = res.data.pagnation;
          this.pagnations.currentPage = this.pagnations.currentPage * 1;
          this.pagnations.pageSize = this.pagnations.pageSize * 1;
        })
        .catch((err) => {
          console.log(err);
        });
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>
<style>
.orderlist {
  height: 100%;
  overflow-y: auto;
}
</style>
